package cool.xinya.ess.controller;

import cool.xinya.ess.common.Result;
import cool.xinya.ess.entity.TSysUser;
import cool.xinya.ess.security.ShiroUser;
import cool.xinya.ess.service.UserService;
import cool.xinya.ess.util.ResultUtil;
import cool.xinya.ess.vo.LoginVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/addUser")
    public Result addUser(@RequestBody TSysUser userInfo) {
        userService.addUser(userInfo);
        return ResultUtil.success();
    }

    @PostMapping(value = "/login")
    public Result webLogin(@RequestBody LoginVo loginVo) {
        ShiroUser user = userService.login(loginVo);
        return ResultUtil.success(user);
    }
}
